import {ref,onMounted,onUnmounted} from 'vue'

export default function useMousePosition(){
    const x = ref(0);
    const y = ref(0);
    const updateMouse = (e: MouseEvent)=>{
      x.value = e.pageX;
      y.value = e.pageY;
    }
    onMounted(()=>{
      document.addEventListener('click',updateMouse)
    })
    onUnmounted(()=>{
      document.removeEventListener('click',updateMouse)
    })
    // 因为是抽离出来的，所以考虑复用要有返回值
    return{x,y}
}